const express = require('express');
const path = require('path');
const querystring = require('querystring');

const app = express();
app.listen(8080);

app.get('/search', (request, response) => {
    response.sendFile(path.resolve(__dirname, 'search.html'));
});

app.get('/login', (request, response) => {
    response.sendFile(path.resolve(__dirname, 'login.html'));
});

app.post('/mylogin', (request, response) => {
    request.on('data', (chunk) => {
        console.log(chunk.toString());
        let obj = querystring.parse(chunk.toString());
        console.log(obj);
    })
    response.send('登录成功');
});

app.get('/shopping', (req, res) => {
    let data = [];
    data.lid = req.query.lid;
    data.count = req.query.count;
    data.uid = req.query.uid;

    res.send(`商品的编号：${data.lid}<br/>购买的数量：${data.count}<br/>用户的编号：${data.uid}`);
});